<template>

    <!---搜索表单-->
    <div class="search-div">
        <el-form label-width="70px" size="small">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="病种类型">
                        <el-input v-model="queryDto.mname"
                                style="width: 150px"
                                placeholder="病例"
                                ></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row style="display:flex">
                <el-button type="primary" size="small" @click="findAllShuju">
                    搜索
                </el-button>
                <el-button size="small" @click="resetData">重置</el-button>
            </el-row>
        </el-form>
    </div>

    <!---数据表格-->
    <el-table :data="list" style="width: 100%">
        <el-table-column prop="mname" label="病例" />
        <el-table-column prop="trait" label="症状" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作" align="center" width="280" #default="scope">
            <el-button type="danger" size="small" @click="deleteById(scope.row)">
                删除
            </el-button>
        </el-table-column>
    </el-table>

    <!--分页条-->
    <el-pagination
                    v-model:current-page="pageParams.page"
                    v-model:page-size="pageParams.limit"
                    :page-sizes="[10, 20, 50, 100]"
                    @size-change="findAllShuju"
                    @current-change="findAllShuju"
                    layout="total, sizes, prev, pager, next"
                    :total="total"
        />
</template>

<script setup>
import { ref,onMounted } from 'vue'; 
import {GetCompilation,DelComilation} from '@/api/compilations';
import { ElMessage,ElMessageBox } from 'element-plus'

//数据模板
let list = ref([])
//分页总条数
let total = ref(0)

const pageParamsForm = {
    page : 1,
    limit: 3
}


const pageParams = ref(pageParamsForm)
// 定义搜索表单数据模型
const queryDto = ref({
    mname: "" 
})
onMounted(()=>{
    findAllShuju()
})
const findAllShuju = async ()=>{
    const {data} = await GetCompilation(pageParams.value.page,pageParams.value.limit,queryDto.value)
    list.value = data.list
    total.value = data.total
}

const deleteById = async (row)=>{
    ElMessageBox.confirm('此操作将永久删除该记录, 是否继续?', 'Warning', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    }).then(async () => {
       const {code } = await DelComilation(row.id)
       if(code === 200) {
            ElMessage.success('删除成功')
            findAllShuju()
       }
    })
}



</script>

<style lang="scss" scoped>

</style>